
'use strict';

/**
	Part of Zombie Navigator
	Copyright © 2015  Zombie Navigator Developers
	
	@file
	@license AGPL-3.0+
*/


/* Used modules */
const _modMeta = require('../platform/meta');
const _modPopup = require('../platform/popup');


/* Private properties */

/**
	List of preference names (see package.json)
	@private
*/
const {
	PREF_NAME_SHOW_HELP
	,
	PREF_NAME_SHOW_HELP_ONCE
} = require('../pref-names.json');


/**
	Help related preferences
	@private
*/
const _preferences = require('../platform/preferences').openPreferences(
	// readable preferences
	[PREF_NAME_SHOW_HELP, PREF_NAME_SHOW_HELP_ONCE]
	,
	// writable preferences
	[PREF_NAME_SHOW_HELP]
);

const _helpPath = 'internal-pages/docs/about.html';
const _licensePath = '../LICENSE';


/**
	@public
*/
const showLicense = () => {
	const modMeta = _modMeta;
	const modPopup = _modPopup;
	
	const licenseURI = modMeta.getURIFromDataPath(_licensePath);
	
	modPopup.openPopup(licenseURI);
};

/**
	@public
*/
const showHelp = () => {
	const modMeta = _modMeta;
	const modPopup = _modPopup;
	
	const helpURI = modMeta.getURIFromDataPath(_helpPath);
	
	modPopup.openPopup(helpURI);
};

/**
	@public
*/
const showHelpIfNecessary = () => {
	const preferences = _preferences;
	
	if (preferences[PREF_NAME_SHOW_HELP]) {
		if (preferences[PREF_NAME_SHOW_HELP_ONCE]) {
			preferences[PREF_NAME_SHOW_HELP] = false;
		}
		
		showHelp();
	}
};


/* Exports */
exports.showLicense = showLicense;
exports.showHelp = showHelp;
exports.showHelpIfNecessary = showHelpIfNecessary;


// vim: ts=4 noet ai

